package com.gt.wc

import com.gt.SCUtil
import org.apache.log4j.Logger
import org.apache.spark.rdd.RDD

object WorldCount_04 {
  private val logger: Logger = Logger.getLogger("WorldCount_02")

  def main(args: Array[String]): Unit = {
    val sc = SCUtil.createLocalSc()
    val rdd1: RDD[String] = sc.makeRDD(Seq("a", "b", "c"))
    val rdd2: RDD[(String, Int)] = rdd1.map(x => (x, 1))

    rdd2.reduceByKey(_+_)
    rdd2.aggregateByKey(0)(_+_,_+_)
    rdd2.foldByKey(0)(_+_)
    rdd2.combineByKey(v=>v,(x:Int,y) => x+y,(x:Int,y:Int) => x+y)

    val str: String = rdd1.reduce((a, b) => a + b)

    val rdd4: RDD[(String, Int)] = rdd2.reduceByKey(_ + _)

    sc.stop()
  }

}
